Skip to content

Add opt-in support for emitting exceptions as log signals#16259

Open
trask wants to merge 13 commits intoopen-telemetry:mainfrom
trask:exceptions-over-log-signal
Open

Add opt-in support for emitting exceptions as log signals#16259
trask wants to merge 13 commits intoopen-telemetry:mainfrom
trask:exceptions-over-log-signal

Conversation

@trask
Copy link
Copy Markdown
Member

@trask trask commented Feb 22, 2026

Span events are in the process of being deprecated.

This starts to add opt-in support for emitting exceptions as logs (as opposed to span events).

Follows semantic conventions proposal: open-telemetry/semantic-conventions#3414

See #16049 for how this will be used, this PR is just laying the foundation.

@trask trask force-pushed the exceptions-over-log-signal branch 2 times, most recently from e5ccd7d to bc09a65 Compare February 22, 2026 20:13
@trask trask force-pushed the exceptions-over-log-signal branch from bc09a65 to 161b795 Compare February 22, 2026 21:18
@trask trask force-pushed the exceptions-over-log-signal branch from 161b795 to 0d2f88b Compare February 25, 2026 03:20
@trask trask marked this pull request as ready for review February 25, 2026 04:24
@trask trask requested a review from a team as a code owner February 25, 2026 04:24
if (emitExceptionAsSpanEvents()) {
span.recordException(error);
}
if (emitExceptionAsLogs() && exceptionEventExtractor != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the extractor is not set the exception would be lost. Is there a plan to introduce a default extractor or do we need to change the instrumenter api to force user to always provide an extractor?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a default

name is {instrumentationName}.exception
severity is WARN

cc @lmolkova

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the default to

  • name: "exception"
  • severity: WARN

based on open-telemetry/semantic-conventions#3311

trask added 2 commits March 2, 2026 16:42
…-signal

# Conflicts:
#	instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java
@trask trask force-pushed the exceptions-over-log-signal branch from ab473e9 to d06b0e9 Compare March 3, 2026 04:35
assertThat(log.getAttributes().get(EXCEPTION_TYPE))
.isEqualTo("java.lang.IllegalStateException");
assertThat(log.getAttributes().get(EXCEPTION_MESSAGE)).isEqualTo("test");
assertThat(log.getAttributes().get(EXCEPTION_STACKTRACE)).isNotNull();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    OpenTelemetryAssertions.assertThat(logs.get(0))
        // Should be WARN (from setExceptionEventExtractor), not ERROR (from CONSUMER span kind)
        .hasSeverity(Severity.WARN)
        .hasEventName("messaging.client.operation.exception")
        .hasAttributesSatisfyingExactly(equalTo(EXCEPTION_TYPE, "java.lang.IllegalStateException"), 
            equalTo(EXCEPTION_MESSAGE, "test"),
            satisfies(EXCEPTION_STACKTRACE, AbstractAssert::isNotNull));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants